package edu.java.lectures.lec10.exceptions.example.cafe;

import edu.java.lectures.lec10.exceptions.example.cafe.exceptions.TooColdException;
import edu.java.lectures.lec10.exceptions.example.cafe.exceptions.TooHotException;

public class Client {

    private static final String LOG_PREFIX = "[Client]\t";
    private static final int MAX_TEMPERATURE_THRESHOLD = 60;
    private static final int MIN_TEMPERATURE_THRESHOLD = 10;

    public Client() {
    }

    public void drinkCoffee(Coffee cupOfCoffee) throws TooHotException,
	    TooColdException {
	if (cupOfCoffee == null) {
	    throw new IllegalArgumentException(
		    "Invalid argument cupOfCoffe: null.");
	}
	double coffeeTemperature = cupOfCoffee.getTemperature();
	if (coffeeTemperature > MAX_TEMPERATURE_THRESHOLD) {
	    throw new TooHotException("This coffee is too hot for me.",
		    coffeeTemperature);
	}
	if (coffeeTemperature < MIN_TEMPERATURE_THRESHOLD) {
	    throw new TooColdException("The coffee is too cold for me.",
		    coffeeTemperature);
	}
	System.out.println(LOG_PREFIX
		+ "Drinking perfect coffee with temperature "
		+ cupOfCoffee.getTemperature());
    }
}
